//
//  GYAboutUsViewController.m
//  GoodLuck
//
//  Created by apple on 2018/6/14.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYAboutUsViewController.h"
#import "GYNetWorkTools.h"
@interface GYAboutUsViewController ()

@property (weak, nonatomic) IBOutlet UILabel *currentVersionLable;
@property (weak, nonatomic) IBOutlet UILabel *scoreLbale;
@property (weak, nonatomic) IBOutlet UILabel *updateVersionLable;
@property (weak, nonatomic) IBOutlet UIImageView *version_redImageView;

@end

@implementation GYAboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

//初始化
- (void)setupUI {
    self.navigationItem.title = @"关于我们";
    NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    self.currentVersionLable.text = [NSString stringWithFormat:@"有味生活电商平台 v%@",currentVersion];
    self.version_redImageView.hidden = YES;
    
    //加载版本
    [GYNetWorkTools requestAppVesion:^(NSDictionary *obj) {
        //NSLog(@"version=====obj=======%@",obj);
        int code = [[obj objectForKey:@"code"] intValue];
        NSDictionary *datas = [obj objectForKey:@"datas"];
        if (code == 200) {
            if ([datas isKindOfClass:[NSDictionary class]]) {
                NSString *version = [datas objectForKey:@"version"];
                if ([version compare:currentVersion] == NSOrderedDescending) {
                    self.version_redImageView.hidden = NO;
                }else {
                    self.version_redImageView.hidden = YES;
                }
            }
        }
    } error:^(NSError *error) {
        NSLog(@"loadAppVsersion=======%@",error);
    }];
    
}

- (IBAction)onClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:
            {
                NSLog(@"跳转到评论界面...");
                //最新跳转评论的地址
                NSString *str = [NSString stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@?action=write-review&mt=8",@"1384768760"];
                //NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1384768760&pageNumber=0&sortOrdering=2&mt=8"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
            }
            break;
            
        case 2:
        {
            NSLog(@"跳转到下载界面...");//itms-apps://itunes.apple.com/cn/app/jie-zou-da-shi/id1384768760?mt=8
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://itunes.apple.com/app/apple-store/id1384768760?pt=118536605&ct=web&mt=8"]];//https://itunes.apple.com/app/apple-store/id1384768760?pt=118536605&ct=web&mt=8
        }
            break;
            
        default:
            break;
    }
}


@end
